/**
 * 
 */
package us.levk.remote.drmaa.client.impl;

import java.net.URL;
import java.util.Map;
import java.util.UUID;

import org.ggf.drmaa.DrmaaException;
import org.ggf.drmaa.JobInfo;

import us.levk.remote.drmaa.common.api.RemoteJobInfo;


/**
 * @author levk
 *
 */
public class JobInfoImpl implements JobInfo {

  final transient Map<URL, Map<Class<?>, Object>> remote;
  final UUID info;
  final URL url;

  JobInfoImpl (Map<URL, Map<Class<?>, Object>> remote, UUID info, URL url) {
    this.info = info;
    this.url = url;
    this.remote = remote;
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobInfo#getJobId()
   */
  @Override public String getJobId () throws DrmaaException {
    return ((RemoteJobInfo) remote.get (url).get (RemoteJobInfo.class)).getJobId (info);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobInfo#getResourceUsage()
   */
  @SuppressWarnings ("rawtypes") @Override public Map getResourceUsage () throws DrmaaException {
    return ((RemoteJobInfo) remote.get (url).get (RemoteJobInfo.class)).getResourceUsage (info);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobInfo#hasExited()
   */
  @Override public boolean hasExited () throws DrmaaException {
    return ((RemoteJobInfo) remote.get (url).get (RemoteJobInfo.class)).hasExited (info);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobInfo#getExitStatus()
   */
  @Override public int getExitStatus () throws DrmaaException {
    return ((RemoteJobInfo) remote.get (url).get (RemoteJobInfo.class)).getExitStatus (info);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobInfo#hasSignaled()
   */
  @Override public boolean hasSignaled () throws DrmaaException {
    return ((RemoteJobInfo) remote.get (url).get (RemoteJobInfo.class)).hasSignaled (info);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobInfo#getTerminatingSignal()
   */
  @Override public String getTerminatingSignal () throws DrmaaException {
    return ((RemoteJobInfo) remote.get (url).get (RemoteJobInfo.class)).getTerminatingSignal (info);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobInfo#hasCoreDump()
   */
  @Override public boolean hasCoreDump () throws DrmaaException {
    return ((RemoteJobInfo) remote.get (url).get (RemoteJobInfo.class)).hasCoreDump (info);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobInfo#wasAborted()
   */
  @Override public boolean wasAborted () throws DrmaaException {
    return ((RemoteJobInfo) remote.get (url).get (RemoteJobInfo.class)).wasAborted (info);
  }
}
